<?php
/**
 * @author Minh Luan
 * @copyright 2012
 */
include "../service/eventService.php";
include "../service/imageService.php";
if(isset($_POST["titleVn"]))
{
    $flash = $_FILES["flash"];
    $title_vn = $_POST["titleVn"];
    $title_en = $_POST["titleEn"];
    $content_en = $_POST["contentEn"];
    $content_vn = $_POST["contentVn"];
    $status = $_POST["status"];
    //New Event (without flash)
    addEvent($title_en, $title_vn, $content_en, $content_vn, $status);
    //Get last ID
    $id = getLastId();
    if($status == 1) updateEventStatus($id, 0);
    if($id > 0){
        if($flash["type"] == "application/x-shockwave-flash" 
        ||$flash["type"] == "application/x-shockwave-flash2-preview" 
        ||$flash["type"] == "application/futuresplash" 
        ||$flash["type"] == "image/vnd.rn-realflash" )
          {
          if ($flash["error"] > 0)
            {
            echo "Error: " . $flash["error"] . "<br />";
            echo "<script>window.location.href='../admin/event-detail.php?id=$id&msg=1'</script>";
            }
          else
            {
            $flashResult = move_uploaded_file($flash["tmp_name"], "../images/event/".$id.".swf");
                if($flashResult){
                    updateEventFlash($id, $id.".swf");
                        echo "move thanh cong va cap nhat db";
                }else{
                    echo "move failed";
                }
            }
          }else{
            echo "<script>window.location.href='../admin/event-detail.php?id=$id&msg=1'</script>";
          }
        echo "<script>window.location.href='../admin/event-detail.php?id=$id&msg=2'</script>";    
    }else{
        echo "<script>window.location.href='../admin/event-detail.php?id=$id&msg=0'</script>";
    }
}else{
    echo "<script>window.location.href='../admin/event-detail.php'</script>";
}


?>